package com.fmdj.bff.driver.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.fmdj.bff.driver.controller.form.RemoveLocationCacheForm;
import com.fmdj.bff.driver.controller.form.UpdateLocationCacheForm;
import com.fmdj.bff.driver.controller.form.UpdateOrderLocationCacheForm;
import com.fmdj.bff.driver.service.DriverPositionService;
import com.fmdj.common.util.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/driver/position")
@Tag(name = "DriverPositionController", description = "司机定位服务Web接口")
@Slf4j
public class DriverPositionController {

    @Autowired
    DriverPositionService driverPositionService;

    @PostMapping("/updatePositionCache")
    @Operation(summary = "更新司机缓存GPS定位")
//    @SaCheckLogin
    public CommonResult updatePositionCache(@Valid @RequestBody UpdateLocationCacheForm form) {
//部署时要给解开
//        long driverId = StpUtil.getLoginIdAsLong();
//        form.setDriverId(driverId);

        //测试 手动给数据
        form.setDriverId(form.getDriverId());

        driverPositionService.updatePositionCache(form);
        return CommonResult.ok();
    }

    @PostMapping("/removePositionCache")
    @Operation(summary = "删除司机位置信息")
    @SaCheckLogin
    public CommonResult removePositionCache(@Valid @RequestBody RemoveLocationCacheForm form) {
        long driverId = StpUtil.getLoginIdAsLong();
        form.setDriverId(driverId);
        driverPositionService.removePositionCache(form);
        return CommonResult.ok();
    }

    @PostMapping("/updateOrderPositionCache")
    @Operation(summary = "更新订单位置缓存")
    @SaCheckLogin
    public CommonResult updateOrderPositionCache(@Valid @RequestBody UpdateOrderLocationCacheForm form) {
        driverPositionService.updateOrderPositionCache(form);
        return CommonResult.ok();
    }
}
